package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.service.IGymCoachService;
import com.ruoyi.system.service.IGymCoachTypeService;
import com.ruoyi.system.service.ISysConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GymCoach;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教练Controller
 * 
 * @author ruoyi
 * @date 2024-04-22
 */
@Controller
@RequestMapping("/system/coach")
public class GymCoachController extends BaseController
{
    private String prefix = "system/coach";

    @Autowired
    private IGymCoachService gymCoachService;

    @RequiresPermissions("system:coach:view")
    @GetMapping()
    public String coach()
    {
        return prefix + "/coach";
    }

    /**
     * 查询教练列表
     */
    @RequiresPermissions("system:coach:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GymCoach gymCoach)
    {
        startPage();
        List<GymCoach> list = gymCoachService.selectGymCoachList(gymCoach);
        return getDataTable(list);
    }

    /**
     * 导出教练列表
     */
    @RequiresPermissions("system:coach:export")
    @Log(title = "教练", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GymCoach gymCoach)
    {
        List<GymCoach> list = gymCoachService.selectGymCoachList(gymCoach);
        ExcelUtil<GymCoach> util = new ExcelUtil<GymCoach>(GymCoach.class);
        return util.exportExcel(list, "教练数据");
    }

    /**
     * 新增教练
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教练
     */
    @RequiresPermissions("system:coach:add")
    @Log(title = "教练", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GymCoach gymCoach)
    {
        return toAjax(gymCoachService.insertGymCoach(gymCoach));
    }

    /**
     * 修改教练
     */
    @RequiresPermissions("system:coach:edit")
    @GetMapping("/edit/{coachId}")
    public String edit(@PathVariable("coachId") Long coachId, ModelMap mmap)
    {
        GymCoach gymCoach = gymCoachService.selectGymCoachByCoachId(coachId);
        mmap.put("gymCoach", gymCoach);
        return prefix + "/edit";
    }

    /**
     * 修改保存教练
     */
    @RequiresPermissions("system:coach:edit")
    @Log(title = "教练", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GymCoach gymCoach)
    {
        return toAjax(gymCoachService.updateGymCoach(gymCoach));
    }

    /**
     * 删除教练
     */
    @RequiresPermissions("system:coach:remove")
    @Log(title = "教练", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gymCoachService.deleteGymCoachByCoachIds(ids));
    }
}
